package com.ruoyi.web.controller.mixuebingcheng;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mixuebingcheng.domain.vo.ViewStarVo;
import com.ruoyi.mixuebingcheng.domain.bo.ViewStarBo;
import com.ruoyi.mixuebingcheng.service.IViewStarService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * VIEW
 *
 * @author ruoyi
 * @date 2023-10-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mixuebingcheng/viewStar")
public class ViewStarController extends BaseController {

    private final IViewStarService iViewStarService;

    /**
     * 查询VIEW列表
     */
    @SaCheckPermission("mixuebingcheng:viewStar:list")
    @GetMapping("/list")
    public TableDataInfo<ViewStarVo> list(ViewStarBo bo, PageQuery pageQuery) {
        return iViewStarService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出VIEW列表
     */
    @SaCheckPermission("mixuebingcheng:viewStar:export")
    @Log(title = "VIEW", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ViewStarBo bo, HttpServletResponse response) {
        List<ViewStarVo> list = iViewStarService.queryList(bo);
        ExcelUtil.exportExcel(list, "VIEW", ViewStarVo.class, response);
    }

    /**
     * 获取VIEW详细信息
     *
     * @param viewStarId 主键
     */
    @SaCheckPermission("mixuebingcheng:viewStar:query")
    @GetMapping("/{viewStarId}")
    public R<ViewStarVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long viewStarId) {
        return R.ok(iViewStarService.queryById(viewStarId));
    }

    /**
     * 新增VIEW
     */
    @SaCheckPermission("mixuebingcheng:viewStar:add")
    @Log(title = "VIEW", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ViewStarBo bo) {
        return toAjax(iViewStarService.insertByBo(bo));
    }

    /**
     * 修改VIEW
     */
    @SaCheckPermission("mixuebingcheng:viewStar:edit")
    @Log(title = "VIEW", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ViewStarBo bo) {
        return toAjax(iViewStarService.updateByBo(bo));
    }

    /**
     * 删除VIEW
     *
     * @param viewStarIds 主键串
     */
    @SaCheckPermission("mixuebingcheng:viewStar:remove")
    @Log(title = "VIEW", businessType = BusinessType.DELETE)
    @DeleteMapping("/{viewStarIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] viewStarIds) {
        return toAjax(iViewStarService.deleteWithValidByIds(Arrays.asList(viewStarIds), true));
    }
}
